package cn.yangliu.security.web;

import cn.yangliu.security.entity.Resources;
import cn.yangliu.security.service.ResourcesService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 杨柳
 * @contact 
 * @date 2019-03-20 00:08
 */
@Controller
@RequestMapping("/resources")
@Slf4j
public class ResourcesController {
    
    @Autowired
    private ResourcesService resourcesService;
    
    /**
     * 新增
     */
    @PostMapping("/save")
    public ModelAndView save(@RequestBody Resources data){
        resourcesService.save(data);

        return new ModelAndView();
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    public ModelAndView update(@RequestBody Resources data){
        resourcesService.updateById(data);

        return new ModelAndView();
    }

    /**
     * 列表查询
     */
    @GetMapping("/list")
    public ModelAndView list(@RequestParam Resources queryPojo, Page<Resources> page){
        IPage<Resources> data = resourcesService.page(page, new QueryWrapper<>(queryPojo));

        return new ModelAndView();
    }

    /**
     * 查询单个
     */
    @GetMapping("/getById/{id}")
    public ModelAndView getById(@PathVariable("id") Long id){
        Resources data = resourcesService.getById(id);

        return new ModelAndView();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public ModelAndView delete(@RequestBody Long[] ids){
        resourcesService.removeByIds(Arrays.asList(ids));
        return new ModelAndView();
    }

}
